<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/maintain/google.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/page.css">
</script>
<style scoped>
    .layui-card-body,
    .layui-card,
    .layui-fluid {
        border: 0;
        background-color: #f2f2f2;
        box-shadow: none;
    }
    .layui-form .layui-form-label{
        font-size: 10px;
        padding-right: 3px;
        float: left;
    }
    .layui-form select,.layui-form input{
        width: 100px;
    }
    .layui-form-item{
        clear: both;
    }
    .form {
        background: #FFF;
        padding: 13px;
        padding-left: 20px;
        margin-top: 11px;
        margin-bottom: 11px;
        height: 26px;
        line-height: 26px;
        font-size: 10px;
        color: #616161;
    }
    .search{
      width: 60px;
      font-size: 11px;
      margin: 0;
      padding: 0 5px;
      border: 0;
      text-align: center;
      background-color: #FF4C4C;
      margin-top: 15px;
      line-height: 22px;
      height: 22px;
    }
    .layui-form-item .layui-inline {
        margin-right: 20px;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form  layuiadmin-card-header-auto" style="border: none;padding: 20px 15px 0;"
            lay-filter="app-content-comment">
            <div class="layui-btn-container layui-col-sm12 layui-col-md12">
                <button class="add-btn search-two-btn" data-type="add">
                    <i class="layui-icon layui-icon-add-circle" style="font-size: 15px; color: #1E9FFF;"></i>
                    <span> 申请调拨</span>
                </button>
            </div>
            <div class="layui-form-item form" style="margin-top: 30px;background-color: #FFF;">
                <div class="layui-form-item layui-col-sm2 layui-col-md2">
                    <label class="layui-form-label">工单状态:</label>
                    <div class="layui-input-block ">
                        <select name="fil05">
                            <option value="">全部</option>
                            <option value="0">未提交</option>
                            <option value="1">待审核</option>
                            <option value="6">OA送审中</option>
                            <option value="9">归档已完成</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-col-sm2 layui-col-md2">
                    <label class="layui-form-label">工单编号:</label>
                    <div class="layui-input-block ">
                        <input type="text" name="fil01" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-col-sm2 layui-col-md2">
                    <label class="layui-form-label">工单名称:</label>
                    <div class="layui-input-block ">
                        <input type="text" name="tcReqName" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-col-sm2 layui-col-md2 ">
                    <label class="layui-form-label">申请时间:</label>
                    <div class="layui-input-block ">
                        <input type="text"  placeholder="请选择日期"
                            name="fil10" id="time1" class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item layui-col-sm2 layui-col-md2" style="position: relative;right: 20px;text-align: center;">
                    <button class="search-two-btn layui-btn-radius" lay-submit lay-filter="LAY-app-order-search"
                        style="background-color:#4C96CF;">
                        <i class="layui-icon layui-icon-search" style="font-size: 10px;"></i>
                        <span>查询</span>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table class="layui-table" id="LAY-app-content-comm" lay-filter="LAY-app-content-comm">
            </table>
            <div class="footer layui-btn-container">
                <button class="search layui-btn layui-btn-radius layui-btn-primary">
                    <i class="layui-icon layui-icon-delete" style="font-size: 15px; color: #FFF;"></i>
                    <span class="labelinp" data_cn="打印" data_en="print" data-lang="toggle">删除</span>
                </button>
            </div>
        </div>

    </div>
</div>
<script type="text/html" id="buttonTpl">
    {{# if(d.fil05=="0"){ }}
    <span>未提交</span> 
    {{# } else if(d.fil05=="1"){ }}
    <span>待审核</span>
    {{# } else if(d.fil05=="2"){ }}
    <span>待执行</span>
    {{# } else if(d.fil05=="6"){ }}
    <span>OA送审中</span>
    {{# } else if(d.fil05=="9"){ }}
    <span>归档已完成</span>
    {{# } }}
</script>
<script>
    layui.use(['admin', 'form', 'user', 'table', 'api', 'laytpl', 'utill', 'laydate'], function () {
        var $ = layui.$,
            admin = layui.admin,
            view = layui.view,
            api = layui.api,
            table = layui.table,
            setter = layui.setter,
            laytpl = layui.laytpl,
            utill = layui.utill,
            laydate = layui.laydate,
            form = layui.form;
        var _TPL = {
            fil05: function (d) {
                if (d.fil05 != null || d.fil05 != '') {
                    if (d.fil05 == "0") {
                        return `<span>未提交</span> `
                    } else if (d.fil05 == "1") {
                        return `<span>待审核</span> `
                    } else if (d.fil05 == "2") {
                        return `<span>待执行</span>`
                    } else if (d.fil05 == "6") {
                        return `<span>OA送审中</span>`
                    } else if (d.fil05 == "9") {
                        return `<span>归档已完成</span>`
                    }
                } else {
                    return '<div></div>'
                }
            }
        }
        form.render(null, 'app-content-comment');
        form.on('submit(LAY-app-order-search)', function (data) {
            var field = data.field;
            rander(field)
        });
        laydate.render({
            elem: `#time1`,
            done: function (value, date, endDate) { }
        });

        rander()

        function rander(field) {
            utill.columnCustom('#LAY-app-content-comm', "FilFileSPListVO", {
                // 自己表格的接口
                url: api.host + api.FilFileBPSelectList,
                where: field,
                templet: _TPL
            });

            //删除按钮
            $('.footer').on('click', '.search', function () {
                var checkStatus = table.checkStatus('#LAY-app-content-comm').data;
                var fil01 = [];
                var fil05 = [];
                checkStatus.forEach(elem => {
                    fil01.push(elem.fil01);
                    fil05.push(elem.fil05);
                })
                if (fil05 && fil01 == '' || fil05 && fil01 == null) {
                    layer.msg('请选择您要删除的工单!')
                } else {
                    admin.req({
                        url: api.host + api.spareParts.del,
                        contentType: 'application/json',
                        dataType: 'json',
                        type: 'post',
                        data: JSON.stringify({ fil05: fil05, fil01: fil01 }),
                        success: function (res) {
                            if (res.data == 0) {
                                table.render()
                                table.reload('#LAY-app-content-comm');
                            }
                        }
                    });
                }
            })

            // 跳转的详情页面(llp)
            table.on('tool(LAY-app-content-comm)', function (obj) {
                var data = obj.data;
                if (obj.event == 'detail') {
                    location.hash = '/set/Applyforallocating/fil01=' + obj.data.fil01;
                    var href = '[data-jump="set/sparecommit"]';
                    sessionStorage.setItem('layui-this', JSON.stringify(href));
                    sessionStorage.setItem('fil05', JSON.stringify(obj.data.fil05));
                }
            })
        }
        //列定制
        utill.columnCustom('#LAY-app-content-comm', "FilFileSPListVO", {
            // 自己表格的接口
            url: api.host + api.FilFileBPSelectList,
            where: {
                fil05: "",
                fil01: "",
                tcReqName: "",
                fil10: ""
            },
            templet: _TPL
        });
        var active = {
            add: function () {
                location.hash = '/set/set_alert/add_form'
            }
        }
        utill.showAndHide('.search-two-btn','FilFileController:insertFilIma');
        $('.search-two-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>